The method "roll()" on the mock object "mockedDie" will always return the value 2. Otherwise, we state that we don't care for jMock to remember, track or in anyway care about the use of the roll() method on mockedDie.
@Test
publicvoid alwaysRoll2()throwsException{
context.checking(new Expectations(){{
ignoring(testDoubleDie).roll();
will(returnValue(2));}});for(int i = 0; i <100; ++i){
assertEquals(2, testDoubleDie.roll());}}
Fix the return value of the faceValue() method
@Test
publicvoid faceValueAlways2(){
context.checking(new Expectations(){{
ignoring(mockedDie).getFaceValue();
will(returnValue(2));}});for(int i = 0; i <100; ++i){
assertEquals(2, mockedDie.getFaceValue());}}
This test method exists in a jMock JUnit 4 Die Skeleton.
Common fixture for the tests
Fix the return value of the roll() method
The method "roll()" on the mock object "mockedDie" will always return the value 2. Otherwise, we state that we don't care for jMock to remember, track or in anyway care about the use of the roll() method on mockedDie.Fix the return value of the faceValue() method
<--Back